<?
$sub_menu = "230300";
include_once("_common.php");

auth_check($auth[$sub_menu], "r");

$token = get_token();

if (!is_numeric($page)) $page = 1;

$sql_common = " from $mw_cash[account_table] ";
$sql_search = " where (1) ";

if ($stx) {
    $sql_search .= " and ( ";
    switch ($sfl) {
        case "mb_id" :
            $sql_search .= " ($sfl = '$stx') ";
            break;
        default : 
            $sql_search .= " ($sfl like '%$stx%') ";
            break;
    }
    $sql_search .= " ) ";
}

if (!$sst) {
    $sst  = "ac_datetime";
    $sod = "desc";
}
$sql_order = " order by $sst $sod ";

$sql = "select count(*) as cnt
        $sql_common
        $sql_search";
$row = sql_fetch($sql);
$total_count = $row[cnt];

$rows = $config[cf_page_rows];
$total_page  = ceil($total_count / $rows);  // 전체 페이지 계산
if ($page == "") { $page = 1; } // 페이지가 없으면 첫 페이지 (1 페이지)
$from_record = ($page - 1) * $rows; // 시작 열을 구함  */

$sql = "select *
        $sql_common
        $sql_search
        $sql_order
        limit $from_record, $rows ";
$result = sql_query($sql);

$write_pages = get_paging($rows, $page, $total_page, "$PHP_SELF?{$qstr}&page=");


$listall = "<a href='$_SERVER[PHP_SELF]'>처음</a>";

$g4[title] = "무통장 입금통보";
include_once ("$g4[admin_path]/admin.head.php");

$colspan = 9;
?>

<script type="text/javascript" src="<?=$g4[path]?>/js/sideview.js"></script>
<script type="text/javascript">
var list_update_php = "";
var list_delete_php = "mw.account.check.delete.php";
</script>

<table width=100%>
<form name=fsearch method=get>
<tr>
    <td width=50% align=left>
        <?=$listall?> (건수 : <?=number_format($total_count)?>)
    </td>
    <td width=50% align=right>
        <select name=sfl class=cssfl>
            <option value='ac_name'>입금자명</option>
            <option value='mb_id'>회원아이디</option>
            <option value='ac_memo'>입금자 메모</option>
            <option value='ac_admin_memo'>관리자 메모</option>
        </select>
        <input type=text name=stx class=ed required itemname='검색어' value='<?=$stx?>'>
        <input type=image src='<?=$g4[admin_path]?>/img/btn_search.gif' align=absmiddle></td>
</tr>
</form>
</table>

<form name=fpointlist method=post>
<input type=hidden name=sst   value='<?=$sst?>'>
<input type=hidden name=sod   value='<?=$sod?>'>
<input type=hidden name=sfl   value='<?=$sfl?>'>
<input type=hidden name=stx   value='<?=$stx?>'>
<input type=hidden name=page  value='<?=$page?>'>
<input type=hidden name=token value='<?=$token?>'>

<table width=100% cellpadding=0 cellspacing=1>
<colgroup width=30>
<colgroup width=90>
<colgroup width=90>
<colgroup width=140>
<colgroup width=100>
<!--<colgroup width=90>-->
<colgroup width=100>
<colgroup width=''>
<colgroup width=60>
<tr><td colspan='<?=$colspan?>' class='line1'></td></tr>
<tr class='bgcol1 bold col1 ht center'>
    <td><input type=checkbox name=chkall value='1' onclick='check_all(this.form)'></td>
    <td><?=subject_sort_link('mb_id')?>회원아이디</a></td>
    <td>별명</td>
    <td><?=subject_sort_link('ac_datetime')?>일시</a></td>
    <td><?=subject_sort_link('ac_name')?>입금자명</a></td>
    <!--<td><?=subject_sort_link('ac_hp')?>핸드폰번호</a></td>-->
    <td><?=subject_sort_link('ac_status')?>상태</a></td>
    <td><?=subject_sort_link('ac_payment')?>입금액</a></td>
    <td><a href="mw.account.form.php"><img src="<?=$g4[admin_path]?>/img/icon_insert.gif"></a></td>
</tr>
<tr><td colspan='<?=$colspan?>' class='line2'></td></tr>
<?
$sum = 0;
for ($i=0; $row=sql_fetch_array($result); $i++) 
{
    if ($row2[mb_id] != $row[mb_id])
    {
        $sql2 = " select mb_id, mb_name, mb_nick, mb_email, mb_homepage, mb_point from $g4[member_table] where mb_id = '$row[mb_id]' ";
        $row2 = sql_fetch($sql2);
    }

    $mb_nick = get_sideview($row[mb_id], $row2[mb_nick], $row2[mb_email], $row2[mb_homepage]);

    $btn_mod = "<a href=\"mw.account.form.php?w=u&ac_id=$row[ac_id]$qstr\"><img src=\"$g4[admin_path]/img/icon_modify.gif\"></a>";
    $btn_del = "<a href=\"javascript:del('mw.account.update.php?w=d&ac_id=$row[ac_id]$qstr')\"><img src=\"$g4[admin_path]/img/icon_delete.gif\"></a>";

    if ($row[ac_status] == "입금신청")
	$row[ac_status] = "<span style='color:#FF6820;'>$row[ac_status]</span>";
    else
	$row[ac_status] = "<span style='color:#888;'>$row[ac_status]</span>";

    $sum += $row[ac_payment];

    $list = $i%2;
    echo "
    <input type=hidden name=ac_id[$i] value='$row[ac_id]'>
    <tr class='list$list col1 ht center'>
        <td><input type=checkbox name=chk[] value='$i'></td>
        <td><a href='?sfl=mb_id&stx=$row[mb_id]'>$row[mb_id]</a></td>
        <td>$mb_nick</td>
        <td>$row[ac_datetime]</td>
        <td>$row[ac_name]</td>
        <!--<td>$row[ac_hp]</td>-->
        <td>$row[ac_status]</td>
        <td align=right>".number_format($row[ac_payment])." 원&nbsp;</td>
        <td> $btn_mod $btn_del </td>
    </tr> ";
} 

if ($i == 0)
    echo "<tr><td colspan='$colspan' align=center height=100 bgcolor=#ffffff>자료가 없습니다.</td></tr>";
else {
    echo "<tr><td colspan='$colspan' class='line2'></td></tr>
<tr class='bgcol1 bold col1 ht center'>
    <td colspan=6>합계</td>
    <td align='right'>".number_format($sum)." 원&nbsp;</td>
    <td>&nbsp;</td>
</tr>";
}
echo "<tr><td colspan='$colspan' class='line2'></td></tr>";
echo "</table>";

$pagelist = get_paging($config[cf_write_pages], $page, $total_page, "$_SERVER[PHP_SELF]?$qstr&page=");
echo "<table width=100% cellpadding=3 cellspacing=1>";
echo "<tr><td width=50%>";
echo "<input type=button class='btn1' value='선택삭제' onclick=\"btn_check(this.form, 'delete')\">";
echo "</td>";
echo "<td width=50% align=right>$pagelist</td></tr></table>\n";

if ($stx)
    echo "<script type='text/javascript'>document.fsearch.sfl.value = '$sfl';</script>\n";

if (strstr($sfl, "mb_id"))
    $mb_id = $stx;
else
    $mb_id = "";
?>
</form>

<script type="text/javascript"> document.fsearch.stx.focus(); </script>

<?
include_once ("$g4[admin_path]/admin.tail.php");
?>
